/* const user = {
  name: "monica",
  age: 17,
};

Object.defineProperty(user, "name", {
  value: "邓哥",
  writable: false, // 是否可写
  enumerable: false, // 是否可以用fon-in遍历
  configurable: false, // 是否可配置
});
console.log(user);
for (const key in user) {
  console.log(key);
} */

/* const obj = {};
Object.defineProperty(obj, "a", {
  get() {
    console.log("first");
    return 1;
  },
  set(val) {
    console.log(val);
  },
});

console.log(obj.a);
obj.a = 100;
console.log(obj.a);
 */

const user = {
  name: "monica",
  age: 17,
  sex: "female",
};

Object.entries(user).forEach(([key, value]) => {
  Object.defineProperty(user, key, {
    get() {
      console.log(`正在读取${key}属性，值为${value}`);
      return value;
    },
    set(val) {
      console.log(`正在设置${key}属性，新的值为${val}`);
      value = val;
    },
  });
});

user.name;
user.age = 10;
console.log(user.age);
